package com.rahms.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rahms.pojo.entity.Medication;
import com.rahms.server.mapper.MedicationMapper;
import com.rahms.server.service.MedicationService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 药品服务实现类
 */
@Service
public class MedicationServiceImpl extends ServiceImpl<MedicationMapper, Medication> implements MedicationService {
    
    @Override
    public List<Medication> getMedicationListByUserId(Long userId) {
        LambdaQueryWrapper<Medication> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Medication::getUserId, userId);
        return this.list(queryWrapper);
    }
    
    @Override
    public List<Medication> searchMedications(Long userId, String keyword) {
        LambdaQueryWrapper<Medication> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Medication::getUserId, userId)
                   .like(keyword != null && !keyword.isEmpty(), Medication::getMedName, keyword);
        return this.list(queryWrapper);
    }
}